package com.jy.modules.cims.component.balance;

import java.math.BigDecimal;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.jy.modules.cims.component.balance.dto.FeeBuildDto;
import com.jy.modules.cims.component.balance.dto.FeeParamDto;
import com.jy.modules.cims.component.balance.factory.ParamFactioryI;
import com.jy.modules.cims.component.balance.servicefee.ServiceFeeI;
import com.jy.modules.cims.data.common.dto.TCMmCostParamDTO;
import com.jy.modules.cims.data.common.dto.TCMmRaisePlanDTO;
import com.jy.modules.cims.data.dto.CreditDetailDto;
import com.jy.modules.cims.data.dto.LoanDetailDto;

@Service("com.jy.modules.cims.component.balance.CalculateExpenseHolder")
public class CalculateExpenseHolder implements CalculateExpenseHolderI {

	
	@Autowired
	@Qualifier("com.jy.modules.cims.component.balance.factory.ParamFactory")
	public ParamFactioryI paramFactiory;
	
	public ServiceFeeI serviceFee;
	
	/**
	 * 费用计算实现方法 -债权
	 * @author zhangmi
	 * @date 2016-8-16 上午10:29:53
	 * @see com.jy.modules.cims.component.balance.CalculateExpenseHolderI#holder(com.jy.modules.cims.component.balance.dto.FeeParamDto)
	 */
	@Override
	public List<CreditDetailDto> holder(FeeParamDto feeParamDto) throws Exception{
		
		//构建参数
		FeeBuildDto feeBuildDto = paramFactiory.build(feeParamDto);
		serviceFee = feeBuildDto.getServiceFee();
		List<CreditDetailDto> creditList = feeBuildDto.getCreditList();
		TCMmCostParamDTO tcmmCostParamDto = feeBuildDto.getTcmmCostParamDto();
		//循环计算费用
		for (CreditDetailDto creditDetailDto : creditList) {
			
			//服务费
			BigDecimal serviceFeeAmount = serviceFee.doServiceFee(creditDetailDto,tcmmCostParamDto);
			creditDetailDto.setServiceCharge(serviceFeeAmount);
			
			//担保金
			BigDecimal guaranteeFeeAmount = serviceFee.doGuaranteeFee(creditDetailDto,tcmmCostParamDto);
			creditDetailDto.setGuaranteeFee(guaranteeFeeAmount);
			
			//保证金
			BigDecimal RiskFeeAmount = serviceFee.doRiskFee(creditDetailDto, tcmmCostParamDto);
			creditDetailDto.setCautionMoney(RiskFeeAmount);
		}
		
		return creditList;
	}

	/**
	 * 贷款费用计算
	 * @author zhangmi
	 * @date 2016-8-16 上午10:32:14
	 * @see com.jy.modules.cims.component.balance.CalculateExpenseHolderI#loanHolder(com.jy.modules.cims.component.balance.dto.FeeParamDto)
	 */
	@Override
	public List<LoanDetailDto> loanHolder(FeeParamDto feeParamDto) throws Exception{
		
		//构建参数
		FeeBuildDto feeBuildDto = paramFactiory.build(feeParamDto);
		serviceFee = feeBuildDto.getServiceFee();
		List<LoanDetailDto> loanList = feeBuildDto.getLoanList();
		TCMmCostParamDTO tcmmCostParamDto = feeBuildDto.getTcmmCostParamDto();
		TCMmRaisePlanDTO tcmmRaisePlanDto = feeBuildDto.getTcmmRaisePlanDto();
		for (LoanDetailDto loanDetailDto : loanList) {
			//服务费
			BigDecimal serviceFeeAmount = serviceFee.doServiceFee(loanDetailDto,tcmmCostParamDto,tcmmRaisePlanDto);
			loanDetailDto.setServiceCharge(serviceFeeAmount);
			
			//担保金
			BigDecimal guaranteeFeeAmount = serviceFee.doGuaranteeFee(loanDetailDto,tcmmCostParamDto,tcmmRaisePlanDto);
			loanDetailDto.setGuaranteeFee(guaranteeFeeAmount);
			
			//保证金
			BigDecimal RiskFeeAmount = serviceFee.doRiskFee(loanDetailDto, tcmmCostParamDto,tcmmRaisePlanDto);
			loanDetailDto.setCautionMoney(RiskFeeAmount);
		}
		
		return loanList;
	}
}
